package sign_in

import (
	"wx-uniapp-go/internal/repository/dto"
	"wx-uniapp-go/internal/server/ctxop"
	"wx-uniapp-go/internal/server/echo"
	"wx-uniapp-go/internal/service"

	"github.com/gin-gonic/gin"
)

// SignIn 签到
func SignIn(c *gin.Context) {
	ctx := echo.TraceCtx(c)
	userId := ctxop.GetUser(ctx).Id
	resp, err := service.NewSignInService().SignIn(ctx, userId)
	if err != nil {
		echo.Fail(c).Error(err)
		return
	}
	echo.Success(c, resp)
}

// GetSignInStatus 获取签到状态
func GetSignInStatus(c *gin.Context) {
	ctx := echo.TraceCtx(c)
	userId := ctxop.GetUser(ctx).Id
	resp, err := service.NewSignInService().GetSignInStatus(ctx, userId)
	if err != nil {
		echo.Fail(c).Error(err)
		return
	}
	echo.Success(c, resp)
}

// ListSignInRecords 获取签到记录列表
func ListSignInRecords(c *gin.Context) {
	var req dto.ListSignInRecordReq
	if err := c.ShouldBindQuery(&req); err != nil {
		echo.Fail(c).Error(err)
		return
	}

	ctx := echo.TraceCtx(c)
	userId := ctxop.GetUser(ctx).Id
	resp, err := service.NewSignInService().ListSignInRecords(ctx, userId, &req)
	if err != nil {
		echo.Fail(c).Error(err)
		return
	}
	echo.Success(c, resp)
}
